import { Controller, Post, Body, Get, Param, Req, UseGuards, ParseIntPipe } from '@nestjs/common';
import { PaymentService } from './payment.service';
import { CreatePaymentDto } from './dto/create-payment.dto';
import { ApiTags, ApiOperation, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../common/jwt-auth.guard';

@ApiTags('支付')
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Controller('payment')
export class PaymentController {
  constructor(private readonly paymentService: PaymentService) {}

  @Post()
  @ApiOperation({ summary: '发起支付' })
  async create(@Req() req, @Body() dto: CreatePaymentDto) {
    return this.paymentService.create(req.user, dto);
  }

  @Get('order/:orderId')
  @ApiOperation({ summary: '查询订单支付状态' })
  async findByOrder(@Req() req, @Param('orderId', ParseIntPipe) orderId: number) {
    return this.paymentService.findByOrder(req.user, orderId);
  }
}
